<?php
class hrd_sakit_model extends MY_Model {
	var $nama_tabel = 'hrd_sakit';
	
	function GetJSON() {
		$ls_sql	= "	SELECT	b.nama_karyawan, a.id_sakit_pk, a.id_karyawan_fk, a.jml_hari, a.ket_sakit, to_char(a.tgl_surat, 'dd/mm/yyyy') tgl_surat, to_char(a.tgl_mulai, 'dd/mm/yyyy') tgl_mulai, to_char(a.tgl_selesai, 'dd/mm/yyyy') tgl_selesai, a.nama_dokter, a.nama_rumah_sakit
					FROM	".$this->nama_tabel." a
					LEFT JOIN hrd_karyawan b ON a.id_karyawan_fk = b.id_karyawan_pk
					WHERE	(UPPER(id_sakit_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(id_sakit_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(ket_sakit,'')) LIKE '%".strtoupper(post('keyword'))."%')
					AND a.tgl_surat >= to_date('".post('tgl_awal')."', 'dd/mm/yyyy')
					AND a.tgl_surat <= to_date('".post('tgl_akhir')."', 'dd/mm/yyyy')
					AND a.id_karyawan_fk like '%".post('id_karyawan_cari')."%'
					ORDER BY ".(post('sort')=='' ? 'id_sakit_pk' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );
					// print_r($ls_sql);
	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			$this->db->delete($this->nama_tabel, array('id_sakit_pk' => $arr_rule['id_sakit_pk']));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	function GenerateId() {
		$sql = "select * 
				from ( 
					select * 
					from hrd_sakit
					order by id_sakit_pk desc
					)
				where ROWNUM <= 1
				";
		$data = $this->db->query($sql)->row_array();

		if (count($data) == 0) {
			return 1;
		} else {
			return $data['id_sakit_pk']+1;
		}
	}

}
?>